﻿using System;
using LambdaGp.Core;

namespace LambdaGp.Operators.Functions.ConditionalFunctions
{
    public class IfThenElseFunction : TernaryFunction
    {
        public IfThenElseFunction()
            : base("if-then-else")
        {
        }

        protected override Func<double> CompileTernaryToFunc(Individual individual, Func<double> first, Func<double> second, Func<double> third)
        {
            return
                () =>
                {
                    if (first() > 0)
                    {
                        return second();
                    }
                    else
                    {
                        return third();
                    }
                };
        }
    }
}